package com.javabasic.algorithm.sword_of_offer;

import com.javabasic.algorithm.leetcode.CountAndSay;

/**
 * @author xiongmin
 * @version 0.0.1
 * @description Created by work on 2021/10/15 9:32 下午
 * @see
 */
public class 外观数列 {

    public static void main(String[] args) {
        countAndSay(4);
    }

    /**
     * 暴力解法 / 递归解法
     * @param n
     * @return
     */
    public static String countAndSay(int n) {
        if (n == 1) return "1";
        if (n == 2) return "11";
        String tagStr = "11", temp;
        int len, tag;
        for (int i = 3; i <= n; i++) {
            len = tagStr.length();
            temp = "";
            tag = 1;
            for (int j = 1; j < len; j++) {
                if (tagStr.charAt(j) == tagStr.charAt(j-1)) {
                    tag++;
                } else {
                    temp = temp + tag + tagStr.charAt(j-1);
                    tag = 1;
                }
            }
            temp = temp + tag + tagStr.charAt(len-1);
            tagStr = temp;
            System.out.println(tagStr);
        }

        return tagStr;
    }
}
